Skip to content

bsn: support field name shorthand#24526

Merged
cart merged 5 commits into
bevyengine:mainfrom
cart:bsn-name-shorthand
Jun 10, 2026
Merged

bsn: support field name shorthand#24526
cart merged 5 commits into
bevyengine:mainfrom
cart:bsn-name-shorthand

Conversation

@cart

@cart cart commented Jun 4, 2026

Copy link
Copy Markdown
Member

Objective

bsn! should support Rust's "name shorthand syntax":

let value = 10;
Foo { value }

Solution

Add support, both for normal types and "props":

let value = 10;
bsn! {
  Foo { value }
}

let value = 10;
bsn! {
  @Foo { @value }  
}

This also changes generated internal bsn! variables to use __X formatting everywhere to avoid conflicts with user-defined variables (we were already using this strategy in some places ... this just uses it everywhere).

Testing

  • added a test

@cart cart added this to the 0.19 milestone Jun 4, 2026
@cart cart added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Scenes Composing and serializing ECS objects labels Jun 4, 2026
@kfc35 kfc35 added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Jun 6, 2026

@kfc35 kfc35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, have to resolve conflicts

@kfc35 kfc35 added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 6, 2026

@ickshonpe ickshonpe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code generation doesn't match the equivalent explicit version, suppose value is a u32 field:

let value = 10u8;
bsn! {
  Foo { value: value }
}

works because it adds an into() but not with:

let value = 10u8;
bsn! {
  Foo { value }
}

which results in a type mismatch error.

@laundmo

laundmo commented Jun 6, 2026

Copy link
Copy Markdown
Member

This should be added to docs (at least the syntax table) once #24464 is merged

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged S-Blocked This cannot move forward until something else changes and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Jun 6, 2026
@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Blocked This cannot move forward until something else changes labels Jun 9, 2026
@cart cart added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jun 10, 2026
@cart cart enabled auto-merge June 10, 2026 00:05
Comment thread crates/bevy_scene/src/lib.rs Outdated
Co-authored-by: urben1680 <55257931+urben1680@users.noreply.github.com>
@cart cart added this pull request to the merge queue Jun 10, 2026
Merged via the queue into bevyengine:main with commit 90744b0 Jun 10, 2026
38 checks passed
mockersf added a commit that referenced this pull request Jun 10, 2026
# Objective

`bsn!` should support Rust's "name shorthand syntax":

```rust
let value = 10;
Foo { value }
```

## Solution

Add support, both for normal types and "props":

```rust
let value = 10;
bsn! {
  Foo { value }
}

let value = 10;
bsn! {
  @foo { @value }  
}
```

This also changes generated internal bsn! variables to use `__X`
formatting everywhere to avoid conflicts with user-defined variables (we
were already using this strategy in some places ... this just uses it
everywhere).

## Testing

- added a test

---------

Co-authored-by: François Mockers <mockersf@gmail.com>
Co-authored-by: urben1680 <55257931+urben1680@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Scenes Composing and serializing ECS objects C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants